package cn.wu.jishupeizhi.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LoggingAspect {

    @Before("execution(* cn.wu.jishupeizhi.service.*.*(..))")
    public void logBefore(JoinPoint joinPoint) {
        System.out.println("Before实现： Executing: " + joinPoint.getSignature().getName());
    }

    @AfterReturning(pointcut = "execution(* cn.wu.jishupeizhi.service.*.*(..))", returning = "result")
    public void logAfterReturning(JoinPoint joinPoint, Object result) {
        System.out.println("AfterReturning实现： Returning: " + result);
    }

    @Around("execution(* cn.wu.jishupeizhi.service.*.*(..))")
    public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("Around实现：Before executing: " + joinPoint.getSignature().getName());
        Object result = joinPoint.proceed();
        System.out.println("Around实现：After executing: " + joinPoint.getSignature().getName());
        return result;
    }
}
